package h0814;

import java.util.Arrays;
import java.util.Scanner;

/**
  * @description 结队编程
  * @author 不知名帅哥
  * @date 2024/8/14 21:05
  * @version 1.0
*/
public class FormationCoding {
    //本题的意思其实就是让我们求解给定输入数组中，比如用例1中 [1,2,3,4] ，每个数组元素：
    //
    //左边比自己大的元素的个数，设为：leftBiggerCount
    //左边比自己小的元素的个数，设为：leftSmallerCount
    //右边比自己大的元素的个数，设为：rightBiggerCount
    //右边比自己小的元素是的个数，设为：rightSmallerCount
    //当我们求解出每个数组元素的上述信息后，累加每个数组元素的如下计算结果：
    //
    //leftBiggerCount * rightSmallerCount + leftSmallerCount * rightBiggerCount
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] levels= Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        System.out.println(getResult(n,levels));
    }

    private static long getResult(int n, int[] levels) {
        long ans=0;
        for (int i = 0; i < n-1; i++) {
            int mid=levels[i];

            long leftSmallerCount=0;
            long leftBiggerCount=0;
            for (int j = 0; j < i; j++) {
                if (levels[j]>mid){
                    leftBiggerCount++;
                }else if (levels[j]<mid){
                    leftSmallerCount++;
                }
            }

            long rightSmallerCount=0;
            long rightBiggerCount=0;
            for (int j = i+1; j < n; j++) {
                if (levels[j]>mid){
                    rightBiggerCount++;
                }else if (levels[j]<mid){
                    rightSmallerCount++;
                }
            }
            ans+=leftSmallerCount*rightBiggerCount+leftBiggerCount*rightSmallerCount;
        }
        return ans;
    }
}
